﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace MediPlatform.Infeartructure
{
    public interface IBaseRepository<T> where T : class
    {
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="t">实体</param>
        /// <returns>受影响行数</returns>
        Task<int> Create(T t);
        
        /// <summary>
        /// 异步添加
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>添加后的实体</returns>
        Task<T> AddAsync(T entity);
        
        /// <summary>
        /// 修改并保存
        /// </summary>
        /// <param name="t">实体</param>
        /// <returns>受影响行数</returns>
        Task<int> Update(T t);
        
        /// <summary>
        /// 更新实体但不保存
        /// </summary>
        /// <param name="entity">实体</param>
        void UpdateEntity(T entity);
        
        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="entity">实体</param>
        void Delete(T entity);
        
        /// <summary>
        /// 根据ID查询
        /// </summary>
        /// <param name="id">ID</param>
        /// <returns>实体</returns>
        Task<T> GetValue(long id);
        
        /// <summary>
        /// 根据条件查询单个实体
        /// </summary>
        /// <param name="predicate">条件表达式</param>
        /// <returns>实体</returns>
        Task<T?> GetAsync(Expression<Func<T, bool>> predicate);
        
        /// <summary>
        /// 查询所有
        /// </summary>
        /// <returns>查询结果</returns>
        Task<IQueryable<T>> GetAll();
        
        /// <summary>
        /// 获取查询对象
        /// </summary>
        /// <returns>查询对象</returns>
        IQueryable<T> Query();
        
        /// <summary>
        /// 保存更改
        /// </summary>
        /// <returns>受影响行数</returns>
        Task<int> SaveChangesAsync();
    }
}
